﻿/**             © 2008 Avanade Inc. All Rights Reserved.
 * 
 * Author:      Joris Valkonet, Avanade Netherlands
 * 
 * Content:     This class is the implementation of the SMO algorithm
 *                 
 * */
using System;
using System.Collections.Generic;
using System.Text;

namespace Avanade.Datamining.SMO
{
    /**
     * The sigmoid kernel : K(x, y) = tanh(k*<x, y> + c)

     */
    public class SigmoidKernel : Kernel
    {

        private double kappa = 1.0;

        private double c = -1;

        public SigmoidKernel(Instances dataset, int cacheSize, double kappa, double c)
            : base(dataset, cacheSize)
        {
            this.kappa = kappa;
            this.c = c;
            this.data = dataset;
        }

        protected override double evaluate(int id1, int id2, Instance inst1)
        {

            double dotProdx;
            if (id1 == id2)
            {
                dotProdx = dotProd(inst1, inst1);
            }
            else
            {
                dotProdx = dotProd(inst1, data.instances[id2]);
            }

            return Math.Tanh(kappa * dotProdx + c);
        }
    }
}
